package com.pro.framework.api.util;

import cn.hutool.http.HttpGlobalConfig;

import java.net.http.HttpClient;
import java.time.Duration;
import java.util.Collections;
import java.util.Map;

public class HttpUtils {
    private static class Holder {
        private static final HttpClient CLIENT = HttpClient.newBuilder()
                .connectTimeout(Duration.ofSeconds(10))
                .build();
    }

    public static HttpClient getClient() {
        return Holder.CLIENT;
    }
    static {
        HttpGlobalConfig.setTimeout(10000);
    }

    public static Map<String, String> toLowerCaseKeys(Map<String, String> headers) {
        if (headers == null) {
            return Collections.emptyMap();
        }
        return CollUtils.listToMapAllRight(headers.entrySet(), e -> e.getKey().toLowerCase(), Map.Entry::getValue);
    }

}
